package com.hmall.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.user.mapper.UserMapper;
import com.hmall.user.pojo.Address;
import com.hmall.user.service.UserService;
import com.itheima.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper,Address> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<Address> getUserAdderss() {

        LambdaQueryWrapper<Address> wrapper = Wrappers.lambdaQuery(Address.class);
        wrapper.eq(Address::getUserId,ThreadLocalUtil.getUserId());
        List<Address> list = userMapper.selectList(wrapper);
        return list;
    }

    @Override
    public Address getAdderssById(Long addressId) {
        Address address = userMapper.selectById(addressId);
        return address;
    }
}
